﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlueCrest.ConfigManagement.Storage.DB.Data;
using BlueCrest.ConfigManagement.Storage.DB.Service;
using NUnit.Framework;

namespace BlueCrest.ConfigManagement.ORM.NHibernate.Tests.Services
{
    [TestFixture]
    public class ConfigPathAdapterServiceTests
    {
        private IConfigPathAdapterService _configPathAdapterService; 
        
        [SetUp]
        public void SetUp()
        {
            _configPathAdapterService = new ConfigPathAdapterService();
        }

        [Test]
        public void CanAdaptByFindingRootFromCollection()
        {
            var flatEntities = new List<ConfigPathFlatEntity>
                                                          {
                                                              new ConfigPathFlatEntity(1, "Root1"),
                                                              new ConfigPathFlatEntity(2, "Root2"),
                                                              new ConfigPathFlatEntity(3, "Item1InRoot1", 1),
                                                              new ConfigPathFlatEntity(4, "Item2InRoot1", 1),
                                                              new ConfigPathFlatEntity(5, "Item1InRoot2", 2),
                                                              new ConfigPathFlatEntity(6, "Item2InRoot2", 2),
                                                              new ConfigPathFlatEntity(7, "Item3InRoot2", 2),
                                                          };

            var result = _configPathAdapterService.Adapt(flatEntities).ToList();

            Assert.IsNotEmpty(result);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(2, result[0].Children.Count);
            Assert.AreEqual(3, result[1].Children.Count);
        }
    }
}
